package com.ews.onlineexchange.controller;

import java.util.Set;

import javax.enterprise.context.ConversationScoped;
import javax.faces.application.FacesMessage;
import javax.faces.validator.ValidatorException;
import javax.inject.Named;

import com.ews.onlineexchange.model.DataEntity;
import com.ews.onlineexchange.model.QualificationClass;
import com.ews.onlineexchange.model.QualificationLevel;
import com.ews.onlineexchange.service.EntityHome;

@Named
@ConversationScoped
public class QualificationClassHome extends EntityHome<QualificationClass, String> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	
	

	@Override
	public QualificationClass createInstance() {
		QualificationClass instance = super.createInstance();
		instance.addEmptyLevelOption();
		
		return instance;
	}

	@Override
	public String delete() {
		getInstance().setDelFlag(DataEntity.DEL_FLAG_DELETE);
		String result = super.saveAndFlush();
		if (result.equals("saved"))
			return "deleted";
		return null;
	}

	@Override
	public String saveAndFlush() {
		if(getInstance().getRootSectors().size() == 0) {
			FacesMessage message =new FacesMessage("请至少选择一个行业！！");
			 message.setSeverity(FacesMessage.SEVERITY_ERROR);
			throw new ValidatorException(message);
		}
		
		return super.saveAndFlush();
	}
	
	

}
